import java.util.Iterator;
import java.util.Stack;

public class Test {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();

        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);

//        Iterator iterator = stack.iterator();
//
//        while (iterator.hasNext()) {
//            System.out.println(iterator.next());
//        }

//        int len = stack.size();
//        for (int i = 0 ; i < len; i++) {
//            System.out.println(stack.pop());
//        }

        for (int i = 0; !stack.isEmpty(); i++) {
            System.out.println(stack.pop());
        }
    }
    public static void main1(String[] args) {
        Stack<Integer> stack = new Stack<>();

        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);

        for (int i : stack) {
            System.out.println(i);
        }
    }
}
